package com.ymatou.iapi.godmch.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.applyAgentBean;
import com.ymatou.iapi.godmch.parameter.rejectAgentBean;
import com.ymatou.iapi.godmch.parameter.rejectAgentListBean;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.rejectAgentListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;
/**
*拒绝代理列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_rejectAgentList{
	private static rejectAgentListBean bean;
	private static rejectAgentListCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("拒绝代理列表");
	}

	@Before
	public void caseUp() {
		bean=new rejectAgentListBean();
		call=new rejectAgentListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_001() {
		Logger.start(true,"正例-拒绝代理列表-默认");
		try {
			//审核
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			//拒绝
			rejectAgentBean rejectBean=GodmchManageCallService.initRejectAgentBean();
			rejectBean.setMchId(applyBean.getMchId());
			rejectBean.setAgentId(applyCall.getAgentId());
			GodmchManageCallService.rejectAgentCall(rejectBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setPageIndex(1);
			bean.setPageSize(5);
			
			call.setData(bean);
			call.callService();			
			
			org.json.JSONObject jObject=new org.json.JSONObject(call.getList().get(0).toString());
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(1, call.getTotal(), "验证total");
			Logger.verifyEquals(applyCall.getAgentId(), jObject.get("agentId"), "验证agentId");
		//	Logger.verifyEquals(200, jObject.get("areaCode"), "验证areaCode");
			Logger.verifyEquals(applyBean.getMobile(), jObject.get("mobile"), "验证mobile");
			Logger.verifyEquals(applyBean.getCountry(), jObject.get("countryName"), "验证countryName");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_004() {
		Logger.start(true,"正例-拒绝代理列表-mchId不存在");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId()+1);
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setPageIndex(1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(0, call.getTotal(), "验证total");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_005() {
		Logger.start(true,"正例-拒绝代理列表-mchId为空");
		try {

			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(null);
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setPageIndex(1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_006() {
		Logger.start(true,"正例-拒绝代理列表-pageIndex等于0");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setPageIndex(0);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_007() {
		Logger.start(true,"正例-拒绝代理列表-pageIndex等于-1");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setPageIndex(-1);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_008() {
		Logger.start(true,"正例-拒绝代理列表-pageIndex为空");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setPageIndex(null);
			bean.setPageSize(5);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_009() {
		Logger.start(true,"正例-拒绝代理列表-pageSize等于0");
		try {
			
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setPageIndex(1);
			bean.setPageSize(0);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_010() {
		Logger.start(true,"正例-拒绝代理列表-pageSize等于-1");
		try {
			
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setPageIndex(1);
			bean.setPageSize(-1);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_011() {
		Logger.start(true,"正例-拒绝代理列表-pageSize为空");
		try {
			
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setPageIndex(1);
			bean.setPageSize(null);
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_012() {
		Logger.start(true,"正例-拒绝代理列表-显示第二页");
		try {
            //申请1
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			//拒绝1
			rejectAgentBean rejectBean=GodmchManageCallService.initRejectAgentBean();
			rejectBean.setMchId(applyBean.getMchId());
			rejectBean.setAgentId(applyCall.getAgentId());
			GodmchManageCallService.rejectAgentCall(rejectBean);
			//申请2
			applyBean.setMchId(applyBean.getMchId());
			applyBean.setCountry("USA");
			applyBean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			applyBean.setPassword("1111aaaa");
			applyBean.setAppSource(60);
			applyBean.setTerminalSource(0);
			applyBean.setAppKey("appsqSeller_"+applyBean.getMchId());
			applyAgentCall applyCall2=GodmchManageCallService.ApplyAgentCall(applyBean);
			//拒绝2
			 rejectBean=GodmchManageCallService.initRejectAgentBean();
			rejectBean.setMchId(applyBean.getMchId());
			rejectBean.setAgentId(applyCall2.getAgentId());
			GodmchManageCallService.rejectAgentCall(rejectBean);
			
			bean.setMchId(applyBean.getMchId());
			//bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setPageIndex(1);
			bean.setPageSize(1);
			call.setData(bean);
			call.callService();		
			
			org.json.JSONObject jObject=new org.json.JSONObject(call.getList().get(0).toString());
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(2, call.getTotal(), "验证total");
			Logger.verifyEquals(applyCall2.getAgentId(), jObject.get("agentId"), "验证agentId");
		//	Logger.verifyEquals(200, jObject.get("areaCode"), "验证areaCode");
			Logger.verifyEquals(applyBean.getMobile(), jObject.get("mobile"), "验证mobile");
			Logger.verifyEquals(applyBean.getCountry(), jObject.get("countryName"), "验证countryName");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_013() {
		Logger.start(true,"正例-拒绝代理列表-下一页为空,总条数1条,pageIndex=3,pageSize=1");
		try {
			//审核
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			//拒绝
			rejectAgentBean rejectBean=GodmchManageCallService.initRejectAgentBean();
			rejectBean.setMchId(applyBean.getMchId());
			rejectBean.setAgentId(applyCall.getAgentId());
			GodmchManageCallService.rejectAgentCall(rejectBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setPageIndex(3);
			bean.setPageSize(1);
			
			call.setData(bean);
			call.callService();			

			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(1, call.getTotal(), "验证total");;			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	//// 20200514 AgentMode=1 或者 2 都查不到数据
	//因为待审核 表中对应的AgentMode=-2
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_014() {
		Logger.start(true,"正例-拒绝代理列表-AgentMode=1");
		try {
			//审核
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			//拒绝
			rejectAgentBean rejectBean=GodmchManageCallService.initRejectAgentBean();
			rejectBean.setMchId(applyBean.getMchId());
			rejectBean.setAgentId(applyCall.getAgentId());
			GodmchManageCallService.rejectAgentCall(rejectBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setAgentMode(1);
			bean.setPageIndex(1);
			bean.setPageSize(5);
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(0, call.getTotal(), "验证total");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
////20200514 AgentMode=1 或者 2 都查不到数据
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgentList_015() {
		Logger.start(true,"正例-拒绝代理列表-AgentMode=2");
		try {
			//审核
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			//拒绝
			rejectAgentBean rejectBean=GodmchManageCallService.initRejectAgentBean();
			rejectBean.setMchId(applyBean.getMchId());
			rejectBean.setAgentId(applyCall.getAgentId());
			GodmchManageCallService.rejectAgentCall(rejectBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setMobile(applyBean.getMobile());
			bean.setAppKey(applyBean.getAppKey());
			bean.setAgentMode(2);
			bean.setPageIndex(1);
			bean.setPageSize(5);
			
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(0, call.getTotal(), "验证total");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}